package com.syedu.day11.homework;

import com.syedu.util.InputUtil;
import org.apache.commons.lang3.StringUtils;

public class Exercise1 {
    public static void main(String[] args) {
        Exercise1 exercise = new Exercise1();

        //加密手机号码
        //String processPhoneNumber = exercise.processPhoneNumber(InputUtil.getStr("请您输入手机号码: "));
        //System.out.println(processPhoneNumber);

        String processName = exercise.processName(InputUtil.getStr("请您输入姓名:"));
        System.out.println(processName);
    }

    /**
     * 输入手机号码,加密手机号码区间
     * 例如:输入18662210785,结果为186****0785
     */
    public String processPhoneNumber(String phoneNumber) {
        //return phoneNumber.replace(phoneNumber.substring(3, 7), "****");

        return phoneNumber.substring(0, 3) + "*".repeat(4) + phoneNumber.substring(7);
    }

    /**
     * 输入姓名,加密姓名
     * 例如:输入Sherlock,结果为S*******
     */
    public String processName(String name) {
        //StringUtils
        return StringUtils.rightPad(name.substring(0, 1), name.length(), "*");

        //JDK11
        //return name.substring(0,1) + "*".repeat(name.length() - 1);

        //低于JDK11
        /*String firstLetter = name.substring(0, 1);
        for (int i = 0; i < name.length() - 1; i++) {
            firstLetter += "*";
        }
        return firstLetter;*/
    }
}